package com.chenxin.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenxin.wms.domain.IbDetailEntity;
import com.chenxin.wms.domain.vo.IbDetailVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenxin.common.annotation.Log;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.enums.BusinessType;
import com.chenxin.wms.service.IIbDetailService;
import com.chenxin.common.utils.poi.ExcelUtil;
import com.chenxin.common.core.page.TableDataInfo;

/**
 * 入库明细单Controller
 *
 * @author gry
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/wms/ibDetails")
public class IbDetailController extends BaseController {
    @Autowired
    private IIbDetailService ibDetailService;

    /**
     * 查询入库明细单列表
     */
    @PreAuthorize("@ss.hasPermi('wms:ibDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbDetailVO detailVo) {
        startPage();
        List<IbDetailVO> list = ibDetailService.selectIbDetailList(detailVo);
        return getDataTable(list);
    }

    /**
     * 导出入库明细单列表
     */
    @PreAuthorize("@ss.hasPermi('wms:ibDetails:export')")
    @Log(title = "入库明细单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbDetailVO detailVo) {
        List<IbDetailVO> list = ibDetailService.selectIbDetailList(detailVo);
        ExcelUtil<IbDetailVO> util = new ExcelUtil<>(IbDetailVO.class);
        util.exportExcel(response, list, "入库明细单数据");
    }

    /**
     * 获取入库明细单详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:ibDetails:query')")
    @GetMapping(value = {"/", "/{ibDetailId}"})
    public AjaxResult getInfo(@PathVariable(value = "ibDetailId", required = false) Long ibDetailId) {
        if (ibDetailId == null) {
            return error("明细获取失败，【ibDetailId】不能为空");
        }
        return success(ibDetailService.selectIbDetailById(ibDetailId));
    }

    /**
     * 新增入库明细单
     */
    @PreAuthorize("@ss.hasPermi('wms:ibDetails:add')")
    @Log(title = "入库明细单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IbDetailEntity ibDetailEntity) {
        return toAjax(ibDetailService.insertIbDetail(ibDetailEntity));
    }

    /**
     * 修改入库明细单
     */
    @PreAuthorize("@ss.hasPermi('wms:ibDetails:edit')")
    @Log(title = "入库明细单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IbDetailEntity ibDetailEntity) {
        return toAjax(ibDetailService.updateIbDetail(ibDetailEntity));
    }

    /**
     * 删除入库明细单
     */
    @PreAuthorize("@ss.hasPermi('wms:ibDetails:remove')")
    @Log(title = "入库明细单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ibDetailIds}")
    public AjaxResult remove(@PathVariable Long[] ibDetailIds) {
        return success("单据删除成功");
    }
}
